/*************************************************************************
    > File Name    : InternetAddress.cc
    > Author       : LiuLei
    > Mail         : 2261459486@qq.com 
    > Created Time : 2022年11月25日 星期五 10时02分07秒
 ************************************************************************/

#include "../../include/server/InternetAddress.h"
#include <string.h>

InternetAddress::InternetAddress(const string &ip, unsigned short port)
{
    ::bzero(&_serverAddr, sizeof(struct sockaddr_in));
    _serverAddr.sin_family = AF_INET;
    _serverAddr.sin_port = ::htons(port);
    _serverAddr.sin_addr.s_addr = ::inet_addr(ip.c_str());
}

InternetAddress::InternetAddress(const struct sockaddr_in &serverAddr)
: _serverAddr(serverAddr)
{

}

InternetAddress::~InternetAddress()
{

}

string InternetAddress::getIp()
{
    return string(::inet_ntoa(_serverAddr.sin_addr));
}

unsigned short InternetAddress::getPort()
{
    return ::ntohs(_serverAddr.sin_port);
}

const struct sockaddr_in *InternetAddress::getInternetAddrPtr() const
{
    return &_serverAddr;
}
